<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>业务员管理</title>
		<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css"  tppabs="https://www.layui.site/layui/dist/css/layui.css"  media="all">
	</head>
	<body>
		
		<div class="layui-form-item" style="text-align: center;padding: 15px;">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 110px;">输入业务员姓名:</label>
				<div class="layui-input-inline">
				  <input type="text" id="sercrhInfo" readonly="" name="name"  class="layui-input">
				</div>
			</div>
			<div class="layui-inline" style="width: 120px;">
				<div class="layui-input-inline">
					<button type="button" class="layui-btn layui-btn-radius" id="staff">业务员管理</button>
				</div>
			</div>
			<div class="layui-inline" style="width: 100px;">
				<div class="layui-input-inline">
					<button type="button" class="layui-btn layui-btn-radius">业务员业绩</button>
				</div>
			</div>
		</div>
		
		<fieldset class="layui-elem-field layui-border-cyan" style="margin: 15px;">
		    <legend style="font-size: 15px;">员工信息</legend>
		    <div class="layui-field-box">
				<div class="layui-row" style="padding: 5px;">
				    <div class="layui-col-md3">
				      <span>员工姓名：</span><span id="empName" style="color: #0000FF;"></span>
				    </div>
					<div class="layui-col-md3">
					  <span>员工职务：</span><span id="jobName" style="color: #0000FF;"></span>
					</div>
					<div class="layui-col-md3">
					  <span>联系电话：</span><span id="empPhone" style="color: #0000FF;"></span>
					</div>
				    <div class="layui-col-md3">
				      <span>联系地址：</span><span id="empAddress" style="color: #0000FF;"></span>
				    </div>
				</div>
				<div class="layui-row" style="padding: 5px;">
				    <div class="layui-col-md3">
				      <span>采购金额：</span><span id="purchaseAmount" style="color: #FF0000;"></span>
				    </div>
					<div class="layui-col-md3">
					  <span>我方已付：</span><span id="wePaid" style="color: #FF0000;"></span>
					</div>
					<div class="layui-col-md3">
					  <span>销售金额：</span><span id="amountPayable" style="color: #FF0000;"></span>
					</div>
				    <div class="layui-col-md3">
				      <span>客户已付：</span><span id="amountPaid" style="color: #FF0000;"aa</span>
				    </div>
				</div>
		    </div>
		</fieldset>
		
		<fieldset class="layui-elem-field layui-border-cyan" style="margin: 15px;">
		  <legend style="font-size: 15px;">单据记录</legend>
		  <div class="layui-field-box">
		    <div style="width: 49%;display: inline-block;float: left; ">
				<span>采购销售情况</span>
				<table class="layui-hide" lay-filter="purchase" id="purchase"></table>
			</div>
			<div style="width: 49%;display: inline-block;float: left;margin-left: 16px;
">
				<span>详细内容</span>
				<table class="layui-hide" lay-filter="particulars" id="particulars"></table>
			</div>
		  </div>
		</fieldset>
		
		<div id="open" style="display: none;">
			<button class="layui-btn"  lay-submit="" lay-filter="exit">退出</button>
		</div>
		
		<script src="../../layui/layui.js" charset="utf-8"></script>
		<script src="../../js/lay-config.js?v=1.1.0" charset="utf-8"></script>
		<script>
			layui.use(['form', 'table', 'layer','stableSelect'], function(){
				var tree = layui.tree
				    ,layer = layui.layer
					,table = layui.table
					,$ = layui.jquery
					,stableSelect = layui.stableSelect,
					form = layui.form;
					
				stableSelect.render({
				    elem: '#sercrhInfo',
					id: "sercrh",
					toolbar: '#open',
					height: 260,
				    table: {
				        url: '../../../searchSalesmanInfo',
				        cols: [[
							{field:'empId', width:100, title: 'Id', hide:true}
				            ,{field:'empName', width:100, title: '员工姓名'}
				            ,{field:'', width:120, title: '职务',templet:function(obj){
								return obj.employeeJob.jobName
							}}
				            ,{field:'empPhone', width:120, title: '联系电话'}
				            ,{field:'empAddress', width:120, title: '联系地址'}
				        ]]
				    }
				});
				
				
				form.on('submit(exit)' , function(obj){
					$('.sercrh').css('display' , 'none');
				});
				
				table.on('rowDouble(sercrh)' , function(obj){
					//员工信息赋值
					$('#empName').html(obj.data.empName)
					$('#jobName').html(obj.data.employeeJob.jobName)
					$('#empPhone').html(obj.data.empPhone)
					$('#empAddress').html(obj.data.empAddress)
					//搜索框赋值
					$('#sercrhInfo').val(obj.data.empName)
					//隐藏下拉表格
					$('.sercrh').css('display' , 'none');
					//采购销售表重载
					table.reload('purchase', {
					    url:"../../../searchPurchaseMarketUnifyInfo?empId="+obj.data.empId
					});
					table.reload('particulars', {
						url:"../../api/aaa.json"
					}); 
				}
				);
				
				
				//销售采购表单
				table.render({
				    elem: '#purchase'
				    ,url: '../../api/aaa.json'
					,height: 270
				    ,cols: [[
				      {field:'documentNumber', width:160, title: '单据号'}
				      ,{field:'client', width:110, title: '供货商/客户'}
				      ,{field:'warehouseaName', width:95, title: '仓库名称'}
				      ,{field:'amountPayable', width:90, title: '应付金额',templet:function(obj){
						  if(obj.amountPayable != 0){
							  return obj.amountPayable
						  }else{
							  return obj.purchaseAmount
						  }
					  }}
				      ,{field:'amountPaid', width: 90, title:'实付金额',templet:function(obj){
						  if(obj.amountPaid != 0){
							return obj.amountPaid
						  }else{
						    return obj.wePaid
						  }
					  }}
				      ,{field:'', width:120, title: '单据类型',templet:function(obj){
						  var documentNumber = obj.documentNumber;
						  if("XS" === documentNumber.substring(0,2)){
							  return "销售单据"
						  }else if("CG" === documentNumber.substring(0,2)){
							  return "采购单据"
						  }else if("XT" === documentNumber.substring(0,2)){
							  return "销售退货单据"
						  }else if("CT" === documentNumber.substring(0,2)){
							  return "采购退货单据"
						  }
						}}
				    ]],
					done: function (obj) {
						var data = obj.data;
						var purchaseAmount = 0;//采购金额
						var wePaid = 0;//我方已付
						var amountPayable = 0;//销售金额 || 应付金额
						var amountPaid = 0;//客户已付 || 实付金额
						
						for ( var i in data) {//for循环遍历i下标data集合对象
							//hasOwnProperty()判断集合中是否存在当前属性
							if(data[i].hasOwnProperty('purchaseAmount') == true){purchaseAmount+=data[i].purchaseAmount}
							if(data[i].hasOwnProperty('wePaid') == true){wePaid+=data[i].wePaid}
							if(data[i].hasOwnProperty('amountPayable') == true){amountPayable+=data[i].amountPayable}
							if(data[i].hasOwnProperty('amountPaid') == true){amountPaid+=data[i].amountPaid}
						}
						
						//给采购金额、我方已付、销售金额、客户已付赋值
						$('#purchaseAmount').html(purchaseAmount+"元")
						$('#wePaid').html(wePaid+"元")
						$('#amountPayable').html(amountPayable+"元")
						$('#amountPaid').html(amountPaid+"元")
						
					}
				});
				//双击采购销售情况行
				table.on('rowDouble(purchase)', function(obj){
				   //采购销售详情表表格重载
				   table.reload('particulars', {
				       url:"../../../searchJudgeOrderInfo?string="+obj.data.documentNumber
				       
				   }); 
				});
				//采购销售详情表单
				table.render({
				    elem: '#particulars'
				    ,url: '../../api/aaa.json'
					,height: 270
				    ,cols: [[
						{field:'proId', width:100, title: '商品编号'}
				      ,{field:'proName', width:205, title: '商品名称'}
				      ,{field:'unitId', width:80, title: '单位'}
				      ,{field:'proBid', width:80, title: '单价'}
				      ,{field:'pronum', title: '数量', width: 100 }
				      ,{field:'', width:80, title: '总金额',templet:function(obj){
							return obj.proBid * obj.pronum
						}}
				    ]]
				});
				
				//弹出层业务管理员页面
				$("#staff").click(function(){
					layer.open({
						type: 2,
						title: '员工管理',
						scrollbar: false,
						area: ['90%', '100%'],
						content: '../systemSetting/staff.html'
					});
				})
			})
		</script>
	</body>
</html>
